package com.woniuxy.hospital.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniuxy.hospital.entity.HplPrescription;
import com.woniuxy.hospital.hplutils.ResponseEntity;
import com.woniuxy.hospital.service.IHplAdminService;
import com.woniuxy.hospital.service.IHplDrugsService;
import com.woniuxy.hospital.service.IHplPrescriptionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.RequestEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2021-08-12
 */
@Controller
@RequestMapping("/drugs")
public class HplDrugsController {
    /**
     * 进入药房管理系统
     *
     * @return
     */
    @GetMapping("into")
    public String into() {
        return "drugs/drugs";
    }

    @Autowired
    IHplDrugsService drugsService;
    @Autowired
    IHplPrescriptionService prescriptionService;
    @Autowired
    IHplAdminService adminService;

    /**
     * 进入处方列表，首次今日显示最新十条记录
     *
     * @return
     */
    @GetMapping("plist")
    public String plist() {
        return "drugs/list";
    }

    /**
     * 根据患者账号查询订单
     *
     * @param no
     * @return
     */
    @PostMapping("plist")
    @ResponseBody
    public ResponseEntity plist(String no) {
        List<HplPrescription> hplPrescriptions=new ArrayList<>();
        ResponseEntity<List> responseEntity=new ResponseEntity<>();
        responseEntity.setCode(200);
        responseEntity.setMsg("ok");
        if (no == null) {
            hplPrescriptions=prescriptionService.list();
            responseEntity.setData(hplPrescriptions);
        }else{
            //此处缺少查询用户信息的语句
            int id=1;
            HplPrescription hplPrescription=new HplPrescription();
            hplPrescription.setPatientId(id);
            QueryWrapper<HplPrescription> wrapper=new QueryWrapper<>(hplPrescription);
            hplPrescriptions=prescriptionService.list(wrapper);
            responseEntity.setData(hplPrescriptions);
        }

        return responseEntity;
    }

   @GetMapping("confirm")
   @ResponseBody
    public ResponseEntity confirm(int id){
       HplPrescription hplPrescription=new HplPrescription();
       hplPrescription.setId(id);
       hplPrescription.setStatus("已完成");
       prescriptionService.updateById(hplPrescription);
        return ResponseEntity.SUCCESS;
   }

}

